* set path

	global raw "~/agriculture_temperature"
	
	global temp "~/revision_codes/temp"
	global visual "~/revision_codes/visual"
	
	use $raw/data/merged_for_reg, clear
	
	xtset ctycode year


* set reference bin

	drop dd5bin10	

	replace dd5bin30 = dd5bin30 + dd5bin35
	
	drop dd5bin35
	
	tempfile r2 r3	
	
* product-level results (Figure 6,Table S14,Table S15)
	
	
	estimates clear
	foreach x in seawater_catch freshwater_breed seawater_fish freshwater_fish {
	****north****	
		qui reghdfe ln_`x' dd5bin* ///
			c.pre##c.pre c.ssd##c.ssd c.prs##c.prs c.win##c.win ///
			i.pro#c.year##c.year ///
			if inrange(year,1995,2015) & region3==1,  ///
			absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store n_`x'
		parmest , label saving(`"`r2'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("North")

	*****south*****	
		qui reghdfe ln_`x' dd5bin* ///
			c.pre##c.pre c.ssd##c.ssd c.prs##c.prs c.win##c.win ///
			i.pro#c.year##c.year ///
			if inrange(year,1995,2015) & region3==2,  ///
			absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store s_`x'
		parmest , label saving(`"`r3'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("South")	

			preserve 
			use `"`r2'"',clear
			append using `"`r3'"' 
			gen product = "`x'"
			rename id  region
			save $temp/est_fishery_`x',replace
			restore			
					
			}	
	
	esttab n_*, b(4) se(4) keep(dd*bin*) brackets	
	esttab s_*, b(4) se(4) keep(dd*bin*) brackets	
	
	
	clear
	foreach x in seawater_catch freshwater_breed seawater_fish freshwater_fish {

		append using $temp/est_fishery_`x'
	}
	
	// keep temp variables only
	keep if strmatch(parm,"*dd5bin*")
	
	//level varibables
	gen level = 2.5 if strmatch(parm, "dd5bin0")
	replace level = 7.5 if strmatch(parm, "dd5bin5")
	replace level = -2.5 if strmatch(parm, "dd5binNeg")
	*replace level = 12.5 if strmatch(parm, "dd5bin10")
	replace level = 17.5 if strmatch(parm, "dd5bin15")
	replace level = 22.5 if strmatch(parm, "dd5bin20")
	replace level = 27.5 if strmatch(parm, "dd5bin25")
	replace level = 32.5 if strmatch(parm, "dd5bin30")
	*replace level = 37.5 if strmatch(parm, "dd5bin35")

	
	// product name 
	replace product = "Seawater Catch" if strmatch(product,"seawater_catch")
	replace product = "Total Seawater Fish" if strmatch(product,"seawater_fish")
	replace product = "Freshwater Aquaculture" if strmatch(product,"freshwater_breed")
	replace product = "Total Freshwater Fish" if strmatch(product,"freshwater_fish")
		
	rename estimate coef 
	rename stderr se 
	rename min95 ci_l
	rename max95 ci_h
	
	// add zero-value lines
	bysort region product : gen last = _n == _N
	expand 2 if last
	sort region product parm
	replace level = 12.5 if parm==parm[_n-1]
	replace coef = 0 if parm==parm[_n-1]
	replace se = 0 if parm==parm[_n-1]
	replace ci_h = 0 if parm==parm[_n-1]
	replace ci_l = 0 if parm==parm[_n-1]		
	
	save $visual/visual_fishery,replace	
	
	// delete dta data 
	cd $temp/
	fs *.dta
	foreach f in `r(files)'{
	   erase "`f'"
	}	

*****************************Figure S3**************************	
	* set path

	global raw "~/agriculture_temperature"
	
	global temp "~/revision_codes/temp"
	global visual "~/revision_codes/visual"
	
	use $raw/data/merged_for_reg, clear
	
	xtset ctycode year


* set reference bin

	drop dd5bin10	

	
	tempfile r4 r5	
	
* product-level results 
	
	
	estimates clear
	foreach x in seawater_catch freshwater_breed seawater_fish freshwater_fish {
	****north****	
		qui reghdfe ln_`x' dd5bin* ///
			c.pre##c.pre c.ssd##c.ssd c.prs##c.prs c.win##c.win ///
			i.pro#c.year##c.year ///
			if inrange(year,1995,2015) & region3==1,  ///
			absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store n_`x'
		parmest , label saving(`"`r4'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("North")

	*****south*****	
		qui reghdfe ln_`x' dd5bin* ///
			c.pre##c.pre c.ssd##c.ssd c.prs##c.prs c.win##c.win ///
			i.pro#c.year##c.year ///
			if inrange(year,1995,2015) & region3==2,  ///
			absorb(ctycode year) cluster(ctycode proXyear) 
			estimates store s_`x'
		parmest , label saving(`"`r4'"',replace) format(p %8.2f) stars(0.1 0.05 0.01)  idstr("South")	

			preserve 
			use `"`r4'"',clear
			append using `"`r5'"' 
			gen product = "`x'"
			rename id  region
			save $temp/est_fishery_`x',replace
			restore			
					
			}	
	
	esttab n_*, b(4) se(4) keep(dd*bin*) brackets	
	esttab s_*, b(4) se(4) keep(dd*bin*) brackets	
	
	
	clear
	foreach x in seawater_catch freshwater_breed seawater_fish freshwater_fish {

		append using $temp/est_fishery_`x'
	}
	
	// keep temp variables only
	keep if strmatch(parm,"*dd5bin*")
	
	//level varibables
	gen level = 2.5 if strmatch(parm, "dd5bin0")
	replace level = 7.5 if strmatch(parm, "dd5bin5")
	replace level = -2.5 if strmatch(parm, "dd5binNeg")
	*replace level = 12.5 if strmatch(parm, "dd5bin10")
	replace level = 17.5 if strmatch(parm, "dd5bin15")
	replace level = 22.5 if strmatch(parm, "dd5bin20")
	replace level = 27.5 if strmatch(parm, "dd5bin25")
	replace level = 32.5 if strmatch(parm, "dd5bin30")
	*replace level = 37.5 if strmatch(parm, "dd5bin35")

	
	// product name 
	replace product = "Seawater Catch" if strmatch(product,"seawater_catch")
	replace product = "Total Seawater Fish" if strmatch(product,"seawater_fish")
	replace product = "Freshwater Aquaculture" if strmatch(product,"freshwater_breed")
	replace product = "Total Freshwater Fish" if strmatch(product,"freshwater_fish")
		
	rename estimate coef 
	rename stderr se 
	rename min95 ci_l
	rename max95 ci_h
	
	// add zero-value lines
	bysort region product : gen last = _n == _N
	expand 2 if last
	sort region product parm
	replace level = 12.5 if parm==parm[_n-1]
	replace coef = 0 if parm==parm[_n-1]
	replace se = 0 if parm==parm[_n-1]
	replace ci_h = 0 if parm==parm[_n-1]
	replace ci_l = 0 if parm==parm[_n-1]		
	
	save $visual/visual_fishery,replace	
	
	// delete dta data 
	cd $temp/
	fs *.dta
	foreach f in `r(files)'{
	   erase "`f'"
	}	
	
	
	
	
	